<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Scrollable Page Demo</title>
    <style>
        body, html {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
        }

        .menu-bar {
            display: flex;
            justify-content: space-between;
            padding: 10px;
            background-color: #f0f0f0;
        }

        .canvas-container {
            height: 100vh; /* 使画布容器占满视窗高度 */
            overflow-y: scroll; /* 添加滚动条 */
            scroll-behavior: smooth; /* 平滑滚动 */
        }

        .canvas {
            display: flex;
            flex-direction: column;
            align-items: center; /* 默认居中对齐 */
        }

        .page {
            width: 210mm;
            height: 297mm;
            border: 1px solid #ccc;
            margin: 20px 0;
            display: flex;
            justify-content: center;
            align-items: center;
            page-break-after: always;
        }
    </style>
</head>
<body>
    <div class="menu-bar">
        <button id="align-left">左对齐</button>
        <button id="align-center">中间对齐</button>
        <button id="align-right">右对齐</button>
    </div>
    <div class="canvas-container">
        <div class="canvas" id="canvas">
            <!-- 页面内容将通过JS动态添加 -->
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const canvas = document.getElementById('canvas');

            // 生成页面内容
            for (let i = 1; i <= 10; i++) {
                const page = document.createElement('div');
                page.classList.add('page');
                page.textContent = `这是第${i}页`;
                canvas.appendChild(page);
            }

            // 对齐按钮事件
            document.getElementById('align-left').addEventListener('click', () => {
                canvas.style.alignItems = 'flex-start';
            });

            document.getElementById('align-center').addEventListener('click', () => {
                canvas.style.alignItems = 'center';
            });

            document.getElementById('align-right').addEventListener('click', () => {
                canvas.style.alignItems = 'flex-end';
            });
        });
    </script>
</body>
</html>
